﻿using System;
namespace Producers.Taitis.Xtee.Riik.Ee.Producer.Taitis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="toimik2", Namespace="http://producers.taitis.xtee.riik.ee/producer/taitis", Target=typeof(Toimik2))]
    public class Toimik2Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IToimik2 clazz;
        
        public Toimik2Serializer(IToimik2 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("toimiku_number");
            if (clazz.ToimikuNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ToimikuNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ToimikuNumber");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("menetlusseisund");
            if (clazz.Menetlusseisund!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Menetlusseisund))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Menetlusseisund");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lahendiliik");
            if (clazz.Lahendiliik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Lahendiliik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Lahendiliik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lahendi_number");
            if (clazz.LahendiNumber!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LahendiNumber))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LahendiNumber");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("lahendikpv");
            if (clazz.Lahendikpv!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Lahendikpv))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Lahendikpv");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "toimiku_number")) {
                goto toimiku_number;
            }
            else {
                if ((Reader.LocalName == "menetlusseisund")) {
                    goto menetlusseisund;
                }
                else {
                    if ((Reader.LocalName == "lahendiliik")) {
                        goto lahendiliik;
                    }
                    else {
                        if ((Reader.LocalName == "lahendi_number")) {
                            goto lahendi_number;
                        }
                        else {
                            if ((Reader.LocalName == "lahendikpv")) {
                                goto lahendikpv;
                            }
                            else {
                                return;
                            }
                        }
                    }
                }
            }
        toimiku_number:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik2>toimiku_number");
            }
            clazz.ToimikuNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("toimiku_number")).Value;
            goto START;
        menetlusseisund:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik2>menetlusseisund");
            }
            clazz.Menetlusseisund = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("menetlusseisund")).Value;
            goto START;
        lahendiliik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik2>lahendiliik");
            }
            clazz.Lahendiliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lahendiliik")).Value;
            goto START;
        lahendi_number:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik2>lahendi_number");
            }
            clazz.LahendiNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lahendi_number")).Value;
            goto START;
        lahendikpv:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimik2>lahendikpv");
            }
            clazz.Lahendikpv = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("lahendikpv")).Value;
            goto START;
        }
    }
}
